export default {
  setDev(state) {
    state.isDev = true;
  },
  login(state, payload) {
    state.status = payload;
  },
  setLoading(state, payload) {
    state.isLoading = payload;
  },
  setModelling(state, payload) {
    state.isModelling = payload;
  },
  setLoginData(state, payload) {
    state.loginData = payload;
  },
  updateData(state, payload) {
    state.dataConfig = payload.dataConfig;
    state.securityData = payload.securityData;
    state.basicData = payload.basicData;
    state.extentionData = payload.extentionData;
    let basicList = new Array();
    for (let i = 0; i < state.dataConfig.length; i++) {
      if (state.dataConfig[i].is_basic || state.dataConfig[i].is_calc) {
        basicList.push(state.dataConfig[i].title);
      }
    }
    for (let i = 0; i < state.extentionData.length; i++) {
      if (basicList.includes(state.extentionData[i].itemTitle)) {
        state.extentionData.splice(i, 1);
        i--;
      }
    }
  },
  setVerifyData(state, payload) {
    state.verifyData = payload;
  },
  setStaffList(state, payload) {
    state.staffList = payload;
    let nameList = new Array();
    for (let i = 0; i < state.staffList.length; i++) {
      nameList.push(state.staffList[i].clientName);
    }
    state.nameList = nameList;
  },
  setOperateLog(state, payload) {
    state.operateLog = payload;
  },
  setFullData(state, payload) {
    let basicList = new Array();
    for (let i = 0; i < state.dataConfig.length; i++) {
      if (state.dataConfig[i].is_basic || state.dataConfig[i].is_calc) {
        basicList.push(state.dataConfig[i].title);
      }
    }
    //
    let data = new Array();
    for (let i = 0; i < payload.basic_data.length; i++) {
      let b = payload.basic_data[i];
      let e = new Array();
      for (let j = 0; j < payload.extention_data.length; j++) {
        if (!basicList.includes(payload.extention_data[j].itemTitle) &&
          payload.extention_data[j].number == b.number) {
          e.push(payload.extention_data[j]);
        }
      }
      data.push({ basicData: b, extentionData: e });
    }
    state.fullData = data;
  },
  modifyItem(state, payload) {
    if (state.fullData != null) {
      for (let i = 0; i < state.fullData.length; i++) {
        if (payload.number == state.fullData[i].basicData.number) {
          for (let j = 0; j < state.fullData[i].extentionData.length; j++) {
            if (state.fullData[i].extentionData[j].itemTitle == payload.itemTitle) {
              state.fullData[i].extentionData[j].itemValue = payload.itemValue;
            }
          }
        }
      }
    }
    if (payload.number == state.loginData.number) {
      for (let i = 0; i < state.extentionData.length; i++) {
        if (state.extentionData[i].itemTitle == payload.itemTitle) {
          state.extentionData[i].itemValue = payload.itemValue;
        }
      }
    }
  },
  deleteItem(state, payload) {
    if (state.fullData != null) {
      for (let i = 0; i < state.fullData.length; i++) {
        if (payload.number == state.fullData[i].basicData.number) {
          for (let j = 0; j < state.fullData[i].extentionData.length; j++) {
            if (state.fullData[i].extentionData[j].itemTitle == payload.itemTitle) {
              state.fullData[i].extentionData.splice(j, 1);
            }
          }
        }
      }
    }
    if (payload.number == state.loginData.number) {
      for (let i = 0; i < state.extentionData.length; i++) {
        if (state.extentionData[i].itemTitle == payload.itemTitle) {
          state.extentionData.splice(i, 1);
        }
      }
    }
  },
  insertItem(state, payload) {
    if (state.fullData != null) {
      for (let i = 0; i < state.fullData.length; i++) {
        if (payload.number == state.fullData[i].basicData.number) {
          state.fullData[i].extentionData.push(payload);
        }
      }
    }
    if (payload.number == state.loginData.number) {
      state.extentionData.push(payload);
    }
  },
  setViewSize(state, payload) {
    state.viewSize = payload;
  },
  setNotifySource(state, payload) {
    state.notifySource = payload;
  },
  setParams(state, payload) {
    state.config.params = payload;
  },
  setParam(state, payload) {
    state.config.params[payload.name] = payload.value;
  },
}